package com.zsk.shop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zsk.shop.entity.ShopOrder;
import com.zsk.shop.model.params.GopOrderParams;
import com.zsk.shop.model.params.OrderParam;
import com.zsk.shop.model.results.GopOrderListResult;
import com.zsk.shop.model.results.OrderListResult;
import com.zsk.shop.model.results.ShopOrderListResult;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ShopOrderMapper extends BaseMapper<ShopOrder> {

    /**
     * 获取订单列表
     *
     * @param orderStatus
     * @return
     */
    @Select("SELECT order_no, user_no, order_status, create_time FROM shop_order WHERE order_status=#{orderStatus} ORDER BY create_time ASC")
    List<ShopOrder> getList(@Param("orderStatus") String orderStatus);

    /**
     * 获取订单列表
     *
     * @param userNo
     * @param orderStatus
     * @param page
     * @param limit
     * @return
     */
    List<ShopOrderListResult> getOrderList(@Param("userNo") String userNo, @Param("orderStatus") String orderStatus, @Param("page") Integer page, @Param("limit") Integer limit);

    /**
     * 总条数
     *
     * @param userNo
     * @param orderStatus
     * @return
     */
    Integer getOrderCount(@Param("userNo") String userNo, @Param("orderStatus") String orderStatus);


    /**
     * GOP报单列表
     * @param params
     * @param page
     * @param limit
     * @return
     */
    List<GopOrderListResult> getGopOrderList(@Param("params") GopOrderParams params, @Param("page") Integer page, @Param("limit") Integer limit);

    /**
     * 总条数
     * @param params
     * @return
     */
    Integer getGopOrderCount(@Param("params") GopOrderParams params);

    /**
     * GOP获取订单列表
     *
     * @param params
     * @return
     */
    List<OrderListResult> queryGopOrderList(@Param("params") OrderParam params, @Param("page") Integer page, @Param("limit") Integer limit);

    /**
     * GOP获取订单列表
     *
     * @param params
     * @return
     */
    int queryGopOrderCount(@Param("params") OrderParam params);

    /**
     * 获取用户当前月是否有购买过商品
     * @param userNo
     * @param goodsOrderType
     * @return
     */
    @Select("SELECT COUNT(1) FROM shop_order WHERE goods_order_type=#{goodsOrderType} AND user_no=#{userNo} AND DATE_FORMAT(pay_time,'%Y%m')=DATE_FORMAT(CURDATE(), '%Y%m') AND (order_status=10 OR order_status=20 OR order_status=30)")
    int getUserPuyNumber(@Param("userNo") String userNo, @Param("goodsOrderType") Integer goodsOrderType);

}